package com.qf.cosmetology.controller;

import com.qf.cosmetology.entity.Subject;
import com.qf.cosmetology.result.ResponseCode;
import com.qf.cosmetology.result.ResponseData;
import com.qf.cosmetology.service.SubjectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-06-25 16:19:17
 */
@RestController
@RequestMapping("subjects")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "queryById",notes = "通过项目id获取项目详细信息")
    @ApiImplicitParam(name ="id",value = "项目id",dataType = "int")
    @GetMapping("/{id}")
    public ResponseData queryById(@PathVariable Integer id) {
        Subject subject = this.subjectService.queryById(id);
        return new ResponseData(ResponseCode.SUCCESS,subject);
    }

    /**
     * 根据标题查询多条数据
     *
     * @param title 查询标题
     * @return 对象列表
     */
    @GetMapping("/v1/{title}")
    public ResponseData queryByTitle(@PathVariable String title){
        return subjectService.queryByTitle(title);
    }
    @GetMapping("/{offset}/{limit}")
    public ResponseData queryAllByLimit(@PathVariable Integer offset,@PathVariable Integer limit){
        List<Subject> list = this.subjectService.queryAllByLimit(offset,limit);
        return new ResponseData(ResponseCode.SUCCESS,list);
    }
}
